package file1;

import jdk.internal.util.xml.impl.Input;

import java.io.*;
import java.util.Scanner;

public class Test10 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要复制的源文件！");
        String src = scanner.next();
        System.out.println("请输入要复制的目标文件");
        String dest = scanner.next();

        File srcFile = new File(src);
        if (!srcFile.isFile()) {
            System.out.println("当前输入的路径有误,不是一个合法的文件！");
            return;
        }
        try (InputStream inputStream = new FileInputStream(src); OutputStream outputStream = new FileOutputStream(dest)) {
            byte[] buffer = new byte[1024];
            int len;
            while (true) {
                len = inputStream.read(buffer);
                if (len == -1) {
                    break;
                }
                outputStream.write(buffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
